const express = require('express')
const app = express()
app.listen(9000, () => console.log('服务启动'))


// 登录
app.get('/login', (req, res, next) => {
    let { username, password } = req.query
    if (!username) {
        next(101)
        return
    }
    if (!password) {
        next(102)
        return
    }

    res.json({ username, password })
})



// 全局错误处理中间件
app.use((err, req, res, next) => {
    // console.log(err);
    if (err == 101) {
        res.json({ code: 400, message: '请输入账户' })
    }
    if (err == 102) {
        res.json({ code: 400, message: '请输入密码' })
    }
})

